function resolveData(data) {
    let result = [];
    for (let k in data) {
        let str = k + "=" + data[k];
        result.push(str);
    }

    return result.join("&");
}


function myItAjax(options) {
    let xhr = new XMLHttpRequest();

    //把外界传来的参数对象，变为查询字符串
    let qs = resolveData(options.data);

    if (options.method.toUpperCase() === "GET") {
        xhr.open("GET", options.url + "?" + qs);
        xhr.send()
    }
    else if (options.method.toUpperCase() === "POST") {
        xhr.open("POST", options.url);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(qs);
    }

    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            let result = JSON.parse(xhr.responseText);

            options.success(result);
        }
    }
}